.class Lcom/melesta/payment/inapp3/InAppSystem$1;
.super Ljava/lang/Object;
.source "InAppSystem.java"

# interfaces
.implements Lcom/melesta/payment/inapp3/IabHelper$QueryInventoryFinishedListener;


# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
    value = Lcom/melesta/payment/inapp3/InAppSystem;
.end annotation

.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0x0
    name = null
.end annotation


# instance fields
.field final synthetic this$0:Lcom/melesta/payment/inapp3/InAppSystem;


# direct methods
.method constructor <init>(Lcom/melesta/payment/inapp3/InAppSystem;)V
    .locals 0
    .parameter

    .prologue
    .line 81
    iput-object p1, p0, Lcom/melesta/payment/inapp3/InAppSystem$1;->this$0:Lcom/melesta/payment/inapp3/InAppSystem;

    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method


# virtual methods
.method public onQueryInventoryFinished(Lcom/melesta/payment/inapp3/IabResult;Lcom/melesta/payment/inapp3/Inventory;)V
    .locals 15
    .parameter "result"
    .parameter "inventory"

    .prologue
    .line 84
    const-string v11, "payment-inapp"

    const-string v12, "Query inventory finished."

    invoke-static {v11, v12}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 85
    invoke-virtual/range {p1 .. p1}, Lcom/melesta/payment/inapp3/IabResult;->isFailure()Z

    move-result v11

    if-eqz v11, :cond_1

    .line 86
    const-string v11, "payment-inapp"

    new-instance v12, Ljava/lang/StringBuilder;

    invoke-direct {v12}, Ljava/lang/StringBuilder;-><init>()V

    const-string v13, "Failed to query inventory: "

    invoke-virtual {v12, v13}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v12

    move-object/from16 v0, p1

    invoke-virtual {v12, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v12

    invoke-virtual {v12}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v12

    invoke-static {v11, v12}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 153
    :cond_0
    return-void

    .line 90
    :cond_1
    invoke-static {}, Lcom/melesta/engine/EngineActivity;->getInstance()Lcom/melesta/engine/EngineActivity;

    move-result-object v11

    new-instance v12, Lcom/melesta/payment/inapp3/InAppSystem$1$1;

    move-object/from16 v0, p2

    invoke-direct {v12, p0, v0}, Lcom/melesta/payment/inapp3/InAppSystem$1$1;-><init>(Lcom/melesta/payment/inapp3/InAppSystem$1;Lcom/melesta/payment/inapp3/Inventory;)V

    invoke-virtual {v11, v12}, Lcom/melesta/engine/EngineActivity;->runOnGLThread(Ljava/lang/Runnable;)V

    .line 102
    const-string v11, "payment-inapp"

    const-string v12, "Query inventory was successful."

    invoke-static {v11, v12}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 104
    iget-object v11, p0, Lcom/melesta/payment/inapp3/InAppSystem$1;->this$0:Lcom/melesta/payment/inapp3/InAppSystem;

    #getter for: Lcom/melesta/payment/inapp3/InAppSystem;->mContext:Landroid/content/Context;
    invoke-static {v11}, Lcom/melesta/payment/inapp3/InAppSystem;->access$100(Lcom/melesta/payment/inapp3/InAppSystem;)Landroid/content/Context;

    move-result-object v11

    invoke-static {v11}, Lcom/melesta/engine/DatabaseHelper;->getHelper(Landroid/content/Context;)Lcom/melesta/engine/DatabaseHelper;

    move-result-object v3

    .line 105
    .local v3, databaseHelper:Lcom/melesta/engine/DatabaseHelper;
    iget-object v11, p0, Lcom/melesta/payment/inapp3/InAppSystem$1;->this$0:Lcom/melesta/payment/inapp3/InAppSystem;

    invoke-virtual {v11}, Lcom/melesta/payment/inapp3/InAppSystem;->getName()Ljava/lang/String;

    move-result-object v8

    .line 108
    .local v8, systemName:Ljava/lang/String;
    new-instance v11, Lcom/melesta/payment/inapp3/InAppSystem$1$2;

    invoke-direct {v11, p0, v8}, Lcom/melesta/payment/inapp3/InAppSystem$1$2;-><init>(Lcom/melesta/payment/inapp3/InAppSystem$1;Ljava/lang/String;)V

    invoke-virtual {v3, v11}, Lcom/melesta/engine/DatabaseHelper;->getTransactions(Lcom/melesta/engine/DatabaseHelper$IObjectFilter;)Ljava/util/List;

    move-result-object v4

    .line 116
    .local v4, dbTransactions:Ljava/util/List;,"Ljava/util/List<Lcom/melesta/payment/PaymentTransaction;>;"
    invoke-static {v4}, Lcom/melesta/payment/PaymentTransaction;->dump(Ljava/util/List;)V

    .line 118
    invoke-virtual/range {p2 .. p2}, Lcom/melesta/payment/inapp3/Inventory;->getAllPurchases()Ljava/util/List;

    move-result-object v1

    .line 119
    .local v1, allPurchases:Ljava/util/List;,"Ljava/util/List<Lcom/melesta/payment/inapp3/Purchase;>;"
    invoke-interface {v1}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v5

    :goto_0
    invoke-interface {v5}, Ljava/util/Iterator;->hasNext()Z

    move-result v11

    if-eqz v11, :cond_0

    invoke-interface {v5}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v7

    check-cast v7, Lcom/melesta/payment/inapp3/Purchase;

    .line 121
    .local v7, purchase:Lcom/melesta/payment/inapp3/Purchase;
    const/4 v9, 0x0

    .line 122
    .local v9, t:Lcom/melesta/payment/PaymentTransaction;
    invoke-interface {v4}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v6

    .local v6, i$:Ljava/util/Iterator;
    :cond_2
    invoke-interface {v6}, Ljava/util/Iterator;->hasNext()Z

    move-result v11

    if-eqz v11, :cond_3

    invoke-interface {v6}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v10

    check-cast v10, Lcom/melesta/payment/PaymentTransaction;

    .line 123
    .local v10, tr:Lcom/melesta/payment/PaymentTransaction;
    iget-object v11, v10, Lcom/melesta/payment/PaymentTransaction;->paymentSystem:Ljava/lang/String;

    invoke-virtual {v8, v11}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v11

    if-eqz v11, :cond_2

    iget-object v11, v10, Lcom/melesta/payment/PaymentTransaction;->paymentId:Ljava/lang/String;

    iget-object v12, v7, Lcom/melesta/payment/inapp3/Purchase;->mDeveloperPayload:Ljava/lang/String;

    invoke-virtual {v11, v12}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v11

    if-eqz v11, :cond_2

    iget-wide v11, v10, Lcom/melesta/payment/PaymentTransaction;->consumeTime:J

    const-wide/16 v13, -0x1

    cmp-long v11, v11, v13

    if-nez v11, :cond_2

    .line 126
    move-object v9, v10

    .line 131
    .end local v10           #tr:Lcom/melesta/payment/PaymentTransaction;
    :cond_3
    if-nez v9, :cond_5

    .line 133
    new-instance v9, Lcom/melesta/payment/PaymentTransaction;

    .end local v9           #t:Lcom/melesta/payment/PaymentTransaction;
    invoke-direct {v9}, Lcom/melesta/payment/PaymentTransaction;-><init>()V

    .line 134
    .restart local v9       #t:Lcom/melesta/payment/PaymentTransaction;
    iget-object v11, v7, Lcom/melesta/payment/inapp3/Purchase;->mSku:Ljava/lang/String;

    iput-object v11, v9, Lcom/melesta/payment/PaymentTransaction;->paymentId:Ljava/lang/String;

    .line 135
    iget-object v11, p0, Lcom/melesta/payment/inapp3/InAppSystem$1;->this$0:Lcom/melesta/payment/inapp3/InAppSystem;

    invoke-virtual {v11}, Lcom/melesta/payment/inapp3/InAppSystem;->getName()Ljava/lang/String;

    move-result-object v11

    iput-object v11, v9, Lcom/melesta/payment/PaymentTransaction;->paymentSystem:Ljava/lang/String;

    .line 136
    const/4 v11, 0x1

    iput v11, v9, Lcom/melesta/payment/PaymentTransaction;->quantity:I

    .line 137
    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v11

    iput-wide v11, v9, Lcom/melesta/payment/PaymentTransaction;->time:J

    .line 138
    iget-object v11, v7, Lcom/melesta/payment/inapp3/Purchase;->mOriginalJson:Ljava/lang/String;

    iput-object v11, v9, Lcom/melesta/payment/PaymentTransaction;->customData:Ljava/lang/String;

    .line 141
    invoke-virtual {v3, v9}, Lcom/melesta/engine/DatabaseHelper;->saveTransaction(Lcom/melesta/payment/PaymentTransaction;)J

    .line 150
    :cond_4
    :goto_1
    new-instance v2, Lcom/melesta/payment/inapp3/InAppSystem$ConsumeFinishedListener;

    iget-object v11, p0, Lcom/melesta/payment/inapp3/InAppSystem$1;->this$0:Lcom/melesta/payment/inapp3/InAppSystem;

    invoke-direct {v2, v11, v9, v3}, Lcom/melesta/payment/inapp3/InAppSystem$ConsumeFinishedListener;-><init>(Lcom/melesta/payment/inapp3/InAppSystem;Lcom/melesta/payment/PaymentTransaction;Lcom/melesta/engine/DatabaseHelper;)V

    .line 151
    .local v2, consumeFinishedListener:Lcom/melesta/payment/inapp3/InAppSystem$ConsumeFinishedListener;
    iget-object v11, p0, Lcom/melesta/payment/inapp3/InAppSystem$1;->this$0:Lcom/melesta/payment/inapp3/InAppSystem;

    invoke-virtual {v11, v7, v2}, Lcom/melesta/payment/inapp3/InAppSystem;->consume(Lcom/melesta/payment/inapp3/Purchase;Lcom/melesta/payment/inapp3/InAppSystem$ConsumeFinishedListener;)V

    goto :goto_0

    .line 143
    .end local v2           #consumeFinishedListener:Lcom/melesta/payment/inapp3/InAppSystem$ConsumeFinishedListener;
    :cond_5
    iget-wide v11, v9, Lcom/melesta/payment/PaymentTransaction;->time:J

    const-wide/16 v13, -0x1

    cmp-long v11, v11, v13

    if-nez v11, :cond_4

    .line 144
    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v11

    iput-wide v11, v9, Lcom/melesta/payment/PaymentTransaction;->time:J

    .line 145
    iget-object v11, v7, Lcom/melesta/payment/inapp3/Purchase;->mOriginalJson:Ljava/lang/String;

    iput-object v11, v9, Lcom/melesta/payment/PaymentTransaction;->customData:Ljava/lang/String;

    .line 147
    invoke-virtual {v3, v9}, Lcom/melesta/engine/DatabaseHelper;->saveTransaction(Lcom/melesta/payment/PaymentTransaction;)J

    goto :goto_1
.end method
